<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <!-- 搜索框 -->
      <el-input placeholder="请输入内容" v-model="queryInfo.query">
        <el-button slot="append" icon="el-icon-search" @click="search()"></el-button>
      </el-input>
      <!-- 订单列表 -->
      <el-table :data="orderList" style="width: 100%" border stripe center>
        <!-- 索引列 -->
        <el-table-column type="index"></el-table-column>
        <!-- 订单编号 -->
        <el-table-column prop="order_id" label="订单编号"></el-table-column>
        <!-- 订单价格 -->
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <!-- 是否付款 -->
        <el-table-column prop="order_pay" label="是否付款">
          <template slot-scope="scope">
            <!-- 已付款 -->
            <el-button type="success" plain v-if="scope.row.order_pay!=='0'" size="mini">已付款</el-button>
            <!-- 未付款 -->
            <el-button type="danger" plain v-else size="mini">未付款</el-button>
          </template>
        </el-table-column>
        <!-- 是否发货 -->
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <!-- 下单时间 -->
        <el-table-column prop="update_time" label="下单时间">
          <template slot-scope="scope">{{scope.row.update_time | dataFormat}}</template>
        </el-table-column>
        <!-- 操作 -->
        <el-table-column label="操作">
          <template slot-scope="scope">
            {{scope.row}}
            <!-- 编辑按钮 -->
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="editAdressInfo(scope.row)"
            ></el-button>
            <!-- 位置按钮 -->
            <el-button type="success" icon="el-icon-location-outline" size="mini"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 20, 30]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="editAdressDialogVisible"
      width="50%"
      @close="editAdressFromClose()"
    >
      <el-form ref="editAdressFormRef" :model="editAdressForm" label-width="80px" size="mini">
        <el-form-item label="省市区/县">
          <el-cascader
            v-model="editAdressForm.adress1"
            :options="cityData"
            :props="{ expandTrigger: 'hover' }"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址">
          <el-input v-model="editAdressForm.adress2"></el-input>
        </el-form-item>
      </el-form>
      <!-- <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>-->
    </el-dialog>
  </div>
</template>
<script>
import cityData from "/Users/gyx10/vue_project_02/citydata.js";

export default {
  data() {
    return {
      cityData,
      //修改地址表单
      editAdressForm: {
        adress1: [],
        adress2: "",
      },
      // 修改地址对话框是否可视
      editAdressDialogVisible: false,
      // 获取订单列表参数
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 5,
        user_id: "",
        pay_status: "",
        is_send: "",
        order_fapiao_title: "",
        order_fapiao_company: "",
        order_fapiao_content: "",
        consignee_addr: "",
      },
      //   订单列表
      orderList: [],
      //   订单总数
      total: 0,
    };
  },
  created() {
    this.getOrderList();
  },
  methods: {
    //   关闭修改地址对话框
    editAdressFromClose() {
      this.$refs.editAdressFormRef.resetFields();
      this.editAdressForm.adress1 = [];
      this.editAdressForm.adress2 = "";
      this.editAdressDialogVisible = false;
    },
    //   修改订单地址
    editAdressInfo(val) {
      this.editAdressDialogVisible = true;
    },
    //   handleSizeChange
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getOrderList();
    },
    // handleCurrentChange
    handleCurrentChange(newNum) {
      this.queryInfo.pagenum = newNum;
      this.getOrderList();
    },
    //   搜索
    search() {
      this.getOrderList();
    },
    //   获取订单列表
    async getOrderList() {
      console.log("queryInfo:");
      console.log(this.queryInfo);
      // 发起网络请求
      const { data: res } = await this.$http.get("orders", {
        params: this.queryInfo,
      });
      if (res.meta.status !== 200) {
        this.$message.error(res.meta.msg);
      } else {
        //   成功
        this.orderList = res.data.goods;
        this.total = res.data.total;
        console.log("orderList:");
        console.log(this.orderList);
      }
    },
  },
};
</script>
<style lang="less" scoped>
.el-input {
  width: 300px;
  text-align: left;
}
</style>